<?php

namespace app\admin\model;

use think\Model;

/**
 * Health
 */
class Health extends Model
{
    // 表名
    protected $name = 'health';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    public $append = [
        'BMI'
    ];


    public function user(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\User::class, 'user_id', 'id');
    }

    public function getBMIAttr($value,$row)
    {
        if($row['weight'] && $row['height']){
            return $row['weight'] / ($row['height'] / 100) / ($row['height'] / 100);
        }
        return 0;
    }
}